package edu.syr.iis.web.model;

import java.sql.Date;

import javax.persistence.Transient;

import edu.syr.iis.web.util.Key;

public class AnnotationSessionStatistics {
	
	Date startDateTime;
	Date endDateTime;	
	User user;
	
	long totalDuration;
	int numOfSessions;
	
	@Transient
	public String getTotalDurationString()
	{
		long diff = totalDuration; 

		long days = diff / Key.dayInMillis;
		diff = diff % Key.dayInMillis;
		long hours = diff / Key.hourInMillis;
		diff = diff % Key.hourInMillis;
		long minutes = diff / Key.minuteInMillis;
		diff = diff % Key.minuteInMillis;
//		long seconds = diff / Key.secondInMillis;
		
		String returnString = "";
		
		if (days > 0 ) returnString += (Long.toString(days) + " days ");
		if (hours > 0) returnString += Long.toString(hours) + " hours ";
		returnString += Long.toString(minutes) + " minutues";
				
		return returnString;		      						
	}
	
	public Date getStartDateTime() {
		return startDateTime;
	}

	public void setStartDateTime(Date dateTime) {
		startDateTime = dateTime;
	}

	public Date getEndDateTime() {
		return endDateTime;
	}

	public void setEndDateTime(Date dateTime) {
		endDateTime = dateTime;
	}

	
	// Dropping the time part, for  annotationsessionlist.jsp 
	//
	@Transient
	public String getStartDateString()
	{
		if (startDateTime != null)
			return startDateTime.toString().substring(0, 10);
		else
			return null;
	}
	
	// Dropping the time part, for  annotationsessionlist.jsp 
	//
	@Transient
	public String getEndDateString()
	{
		if (endDateTime != null)
			return endDateTime.toString().substring(0, 10);
		else
			return null;
	}
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public long getTotalDuration() {
		return totalDuration;
	}
	public void setTotalDuration(long totalDuration) {
		this.totalDuration = totalDuration;
	}
	public long getNumOfSessions() {
		return numOfSessions;
	}
	public void setNumOfSessions(int numOfSessions) {
		this.numOfSessions = numOfSessions;
	}
	
	public long getAverageDuration() {
		return totalDuration / numOfSessions;
	}
}
